#include "Cube.h"
#include <iostream>
#include "../Games/MyGame.h"

Cube::Cube(int maxFrequency, std::string name) :
		GameEntity(maxFrequency, name)
{
	POINT3D leftFrontTop = {-1.0,1.0,1.0};
	POINT3D rightFrontTop = {1.0,1.0,1.0};
	POINT3D leftBackTop = {-1.0,-1.0,1.0};
	POINT3D rightBackTop = {1.0,-1.0,1.0};
	POINT3D leftFrontBottom = {-1.0,1.0,-1.0};
	POINT3D rightFrontBottom = {1.0,1.0,-1.0};
	POINT3D leftBackBottom = {-1.0,-1.0,-1.0};
	POINT3D rightBackBottom = {1.0,-1.0,-1.0};
	CUBEMESH cubeMesh;
	cubeMesh.leftFrontTop = leftFrontTop;
	cubeMesh.rightFrontTop = rightFrontTop;
	cubeMesh.leftBackTop = leftBackTop;
	cubeMesh.rightBackTop = rightBackTop;
	cubeMesh.leftFrontBottom = leftFrontBottom;
	cubeMesh.rightFrontBottom = rightFrontBottom;
	cubeMesh.leftBackBottom = leftBackBottom;
	cubeMesh.rightBackBottom = rightBackBottom;
	_mesh = cubeMesh;

	COLOR color = {1,1,1};
	setColor(color);
}

Cube::~Cube()
{
}

void Cube::draw()
{	
	GameEngine::Instance()->getRenderer()->translate(getPosition());
	GameEngine::Instance()->getRenderer()->rotate(getOrientation()); // Rotate The Pyramid On It's Y Axis
	GameEngine::Instance()->getRenderer()->drawRectangle(_mesh.leftFrontTop, _mesh.rightFrontTop, _mesh.leftBackTop, _mesh.rightBackTop, getColor());
	GameEngine::Instance()->getRenderer()->drawRectangle(_mesh.leftFrontTop, _mesh.rightFrontTop, _mesh.leftFrontBottom, _mesh.rightFrontBottom, getColor());
	GameEngine::Instance()->getRenderer()->drawRectangle(_mesh.leftFrontTop, _mesh.rightBackTop, _mesh.leftFrontBottom, _mesh.rightBackBottom, getColor());
	GameEngine::Instance()->getRenderer()->drawRectangle(_mesh.leftBackTop, _mesh.rightBackTop, _mesh.leftBackBottom, _mesh.rightBackBottom, getColor());
	GameEngine::Instance()->getRenderer()->drawRectangle(_mesh.rightFrontTop, _mesh.rightBackTop, _mesh.rightFrontBottom, _mesh.rightBackBottom, getColor());
	GameEngine::Instance()->getRenderer()->drawRectangle(_mesh.leftFrontBottom, _mesh.rightFrontBottom, _mesh.leftBackBottom, _mesh.rightBackBottom, getColor());
}

void Cube::actualUpdate(int timePassed)
{
	POINT3D newPosition = {getPosition().x, getPosition().y + _scrollDistance, getPosition().z};
	setPosition(newPosition);
	_scrollDistance = 0;
}
void Cube::onMouseScrolled(int xcoord, int ycoord, int distance){
	_scrollDistance = distance;
}	//If a mouseIsScrolled, this function is called

void Cube::reset(){}

void Cube::onKeyPressed(int){}			//If a key is pressed, this function is called
void Cube::onKeyReleased(int){}		//If a key is released, this function is called

void Cube::onMouseMoved(int, int){}			//If a mouseIsMoved, this function is called
void Cube::onMouseClicked(int, int){}			//If a mouseIsClicked, this function is called

int Cube::getType() {
	return GameEntity::CUBE;
}